package org.jeecg.modules.online.cgform.mapper;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.online.cgform.entity.OnlCgformHead;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.online.cgform.service.IOnlCgformFieldService;

/**
 * @Description: Online表单开发
 * @Author: jeecg-boot
 * @Date: 2019-03-12
 * @Version: V1.0
 */
public interface OnlCgformHeadMapper extends BaseMapper<OnlCgformHead> {
	
	/**
	 * 执行DDL语句
	 * @param sql
	 */
	@InterceptorIgnore(tenantLine = "true")
	public void executeDDL(@Param("sqlStr") String sql);
	
	/**
	 * 执行SQL语句查询集合
	 * @param sql
	 * @return
	 */
	public List<Map<String,Object>> queryList(@Param("sqlStr") String sql);
	
	/**
	 * 查询Online所有的配置表名集合
	 * @return
	 */
	public List<String> queryOnlinetables();
	
	/**
	 * 查询一张表的一条记录
	 * 该查询是查询所有字段即select * from tbname 要想只查询表单展示的数据请使用{@link IOnlCgformFieldService#queryFormData}
	 * @param tbname 表名
	 * @param dataId 数据id
	 * @return
	 */
	public Map<String,Object> queryOneByTableNameAndId(@Param("tbname")String tbname,@Param("dataId")String dataId);

	/**
	 * 执行删除
	 * @param sql
	 */
	public void deleteOne(@Param("sqlStr") String sql);
	
//	public Integer queryMaxCopyVersion();
	
	@Select("select max(copy_version) from onl_cgform_head where physic_id = #{physicId}")
	Integer getMaxCopyVersion(@Param("physicId") String physicId);

	/**
	 * 根据原表id获取所有复制表的表名
	 * @param physicId
	 * @return
	 */
	@Select("select table_name from onl_cgform_head where physic_id = #{physicId}")
	List<String> queryAllCopyTableName(@Param("physicId") String physicId);
	
	@Select("select physic_id from onl_cgform_head GROUP BY physic_id")
	List<String> queryCopyPhysicId();

	/**
	 * 根据编码值查询id
	 * @param code
	 * @return
	 */
	String queryCategoryIdByCode(@Param("code") String code);


	/**
	 * 查询子节点数量
	 * @param tableName
	 * @param pidField
	 * @param pidValue
	 * @return
	 */
	@Select("select count(*) from ${tableName} where ${pidField} = #{pidValue}")
	Integer queryChildNode(@Param("tableName") String tableName, @Param("pidField") String pidField, @Param("pidValue") String pidValue);
}
